//
//  UserCenterHeaderView.m
//  GuShiNews
//
//  Created by huachun on 2019/8/21.
//  Copyright © 2019 Jones. All rights reserved.
//

#import "UserCenterHeaderView.h"
#import "XLPhotoBrowser.h"
#import "HiJonesClass.h"

@interface UserCenterHeaderView ()

@property (nonatomic, strong) UIButton    *News_button;

@property (nonatomic, strong) UIImageView *Img;
@property (nonatomic, strong) UILabel     *Name;
@property (nonatomic, strong) UIButton    *User_sex;

@end

@implementation UserCenterHeaderView

/* 在构造方法中，创建UI*/
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        
        [self addSubview:self.Img];
        [self addSubview:self.Name];
        [self addSubview:self.User_sex];
        [self addSubview:self.Guanzhu];
        [self addSubview:self.Sixin];
        
        self.Guanzhu.userInteractionEnabled = NO;
        self.Sixin.userInteractionEnabled = NO;
        
        _News_button = [[UIButton alloc] initWithFrame:self.Img.frame];
        [_News_button addTarget:self action:@selector(showimage:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_News_button];
    }
    return self;
}

- (void)showimage:(UIButton *)sender{
    
    XLPhotoBrowser *browser = [XLPhotoBrowser showPhotoBrowserWithImages:@[_Model.logo] currentImageIndex:0];
    browser.seletBlock = ^(BOOL tui_ok) {
        
    };
}

- (void)setModel:(UserModel *)Model{
    if (_Model != Model) {
        _Model = Model;
    }
    
    [self.Img sd_setImageWithURL:[NSURL URLWithString:_Model.logo] placeholderImage:[UIImage imageNamed:@"user_logo.png"]];
    _Img.contentMode = UIViewContentModeScaleAspectFill;
    self.Name.hidden = NO;
    self.Name.text=_Model.name;
    
    self.User_sex.hidden=NO;
    if ([_Model.sex isEqualToString:@"False"]) {
        _User_sex.backgroundColor=Bluecolor;
        [_User_sex setImage:[UIImage imageNamed:@"sex_nan"] forState:UIControlStateNormal];
    }else{
        _User_sex.backgroundColor=Fengcolor;
        [_User_sex setImage:[UIImage imageNamed:@"sex_nv"] forState:UIControlStateNormal];
    }
    [_User_sex setTitle:[NSString stringWithFormat:@" %li",(long)[HiJonesClass ageWithDateOfBirth:_Model.briday]] forState:UIControlStateNormal];
    
    if ([UserModel info].userid) {
        if ([[UserModel info].userid isEqualToString:_Model.userid]) {
            _Guanzhu.hidden = YES;
            _Sixin.hidden = YES;
        }
    }
}

-(UIImageView *)Img{
    if (!_Img) {
        _Img                     = [[UIImageView alloc] initWithFrame:CGRectMake(20, 30, 65, 65)];
        _Img.layer.masksToBounds = YES;
        _Img.backgroundColor = backColor;
        _Img.layer.zPosition     = 102;
        _Img.layer.cornerRadius = 32.5;
        _Img.layer.masksToBounds = YES;
        _Img.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _Img;
}

-(UILabel *)Name{
    if (!_Name) {
        _Name = [[UILabel alloc] initWithFrame:CGRectMake(100, 30, RECRWITCH-40, 32.5)];
        [_Name setFont:[UIFont boldSystemFontOfSize:16]];
        [_Name setTextColor:[JonesClass stringTOColor:@"#222222"]];
    }
    return _Name;
}

- (UIButton *)User_sex {
    if (!_User_sex) {
        _User_sex = [[UIButton alloc] initWithFrame:CGRectMake(110, 70, 50, 16)];
        [_User_sex setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _User_sex.titleLabel.font=[UIFont boldSystemFontOfSize:12];
        _User_sex.layer.cornerRadius=8;
    }
    return _User_sex;
}

- (UIButton *)Guanzhu {
    if (!_Guanzhu) {
        _Guanzhu = [[UIButton alloc] initWithFrame:CGRectMake(RECRWITCH/2-120, 130, 100, 30)];
        [_Guanzhu setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _Guanzhu.titleLabel.font=[UIFont systemFontOfSize:14];
        _Guanzhu.layer.cornerRadius=5;
        [_Guanzhu setTitle:@"关注TA" forState:UIControlStateNormal];
        _Guanzhu.backgroundColor = Greencolor;
        _Guanzhu.layer.masksToBounds=YES;
        [_Guanzhu addTarget:self action:@selector(acutndddd:) forControlEvents:UIControlEventTouchUpInside];
        _Sixin.tag = 0;
    }
    return _Guanzhu;
}

- (UIButton *)Sixin {
    if (!_Sixin) {
        _Sixin = [[UIButton alloc] initWithFrame:CGRectMake(RECRWITCH/2+20, 130, 100, 30)];
        [_Sixin setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _Sixin.titleLabel.font=[UIFont systemFontOfSize:14];
        _Sixin.layer.cornerRadius=5;
        [_Sixin setTitle:@"私信TA" forState:UIControlStateNormal];
        _Sixin.backgroundColor = NewsTitleColor;
        _Sixin.layer.masksToBounds=YES;
        _Sixin.tag = 1;
        [_Sixin addTarget:self action:@selector(acutndddd:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _Sixin;
}

- (void)acutndddd:(UIButton *)sendeer{
    _slecktblock(sendeer.tag);
}

@end
